#! /bin/sh -vx
# $Id$
# Copyright 2019 Hironobu Yamashita <h.y.acetaminophen@gmail.com>
# You may freely use, modify and/or distribute this file.

BinDir=${BinDir:-.}
ExeExt=${ExeExt:-}
_eptex=$BinDir/eptex$ExeExt

LC_ALL=C; export LC_ALL;  LANGUAGE=C; export LANGUAGE

TEXMFCNF=$srcdir/../kpathsea; export TEXMFCNF
TEXINPUTS="$srcdir/ptexdir/tests;."; export TEXINPUTS

# check consistency between runtime terminal and log
$_eptex -ini -etex -interaction batchmode -jobname epver1-log pver1.tex >epver1-term.log || exit 1
sed -n 's/^This is \([-A-Za-z]*\), Version [^-]*-\([^ ]*\) \(.*\)/\1 \2/p' \
  epver1-term.log >epver1-term_ed.log || exit 2
sed -n 's/^This is \([-A-Za-z]*\), Version [^-]*-\([^ ]*\) \(.*\)/\1 \2/p' \
  epver1-log.log >epver1-log_ed.log || exit 3
diff epver1-term_ed.log epver1-log_ed.log || exit 4

# check consistency between runtime and version output
$_eptex -version >epver2-self.log || exit 5
sed -n '1 s/^\([-A-Za-z]*\) [^-]*-\([^ ]*\) \(.*\)/\1 \2/p' \
  epver2-self.log >epver2-self_ed.log || exit 6
diff epver1-term_ed.log epver2-self_ed.log || exit 7

# check consistency between version output and version primitives
$_eptex -ini -etex -interaction batchmode -jobname epver2-prim pver2.tex || exit 8
sed -n 's/^Engine \([-A-Za-z]*\) \([^ ]*\) \(.*\)/\1 \2/p' \
  epver2-prim.log >epver2-prim_ed.log || exit 9
diff epver2-self_ed.log epver2-prim_ed.log || exit 10

exit 0

